package com.example.dsplatform.Service.ipml;

import com.example.dsplatform.Dao.Mapper.OrderMapper;
import com.example.dsplatform.Service.OrderService;
import com.example.dsplatform.pojo.Entity.Order;
import com.example.dsplatform.pojo.Entity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceIpml implements OrderService {
    @Autowired
    OrderMapper orderMapper;

    @Override
    public ResponseResult addOrder(Order order) {
        try{
            orderMapper.insert(order);
            return new ResponseResult(200,"添加订单成功");
        }catch(DuplicateKeyException e){
            return new ResponseResult(405,"插入失败，该订单号已存在");
        }


    }

    @Override
    public ResponseResult deleteOrders(Order order) {
        orderMapper.deleteById(order.getOrderNo());
        return new ResponseResult(200,"删除订单成功");
    }

    @Override
    public ResponseResult updateOrders(Order order) {
        orderMapper.updateById(order);
        return new ResponseResult(200,"修改订单成功");
    }


    @Override
    public ResponseResult selectOrders() {

        List list = orderMapper.selectList(null);
        return new ResponseResult(200,"查询订单成功",list);
    }
}
